package com.fengr.basic.service.impl;

import com.fengr.basic.mapper.BasicMapper;
import com.fengr.basic.query.BasicQuery;
import com.fengr.basic.service.IBasicService;
import com.fengr.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class BasicServiceImpl<T> implements IBasicService<T> {
    @Autowired
    private BasicMapper<T> mapper;

    @Override
    public T findOne(Long id) {
        return mapper.findOne(id);
    }

    @Override
    public List<T> loadAll() {
        return mapper.loadAll();
    }

    @Override
    @Transactional
    public void insert(T t) {
        mapper.insert(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public PageList pageList(BasicQuery query) {
        Integer totals = mapper.totals(query);
        List<T> rows = mapper.queryData(query);
        return new PageList(totals, rows);
    }

    @Override
    @Transactional
    public void patchDelete(List<Long> ids) {
        mapper.patchDelete(ids);
    }
}